package br.com.localfloripa.controllers;

import java.io.Serializable;
import java.util.Map;
import java.util.ResourceBundle;

import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

import org.springframework.security.acls.model.NotFoundException;

import br.com.localfloripa.entities.Usuario;

public abstract class MainController implements Serializable {
	
	protected ResourceBundle bundle = ResourceBundle.getBundle("messages.MessageBundle");
	private Integer pageSize = 20;
	
	protected void addMessageINFO(String message) {
		
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
				bundle.getString("messages.sumary.info.confirm"), message )); 
	}
	
	protected void addMessageERROR(String message) {
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
				bundle.getString("messages.sumary.error"), message )); 
	}
	
	public Usuario getLoggedUser() {
		return Usuario.getLoggedUser();
	}
	
	protected String getRequestParameter (String key) throws Exception {
		
		ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
		Map<String, String> parameterMap = context.getRequestParameterMap();
		
		String param = null;
		if (parameterMap.containsKey(key)) {
			param = parameterMap.get(key);
		} else {
			throw new NotFoundException(bundle.getString(""));
		}
		return param;				
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	
	
}
